/**
 * Created by Administrator on 2018/10/5 0005.
 */
$(function () {
    $("#ComListCheckAll").click(function () {

        if ($(this).children(".text").text() == "全选") {
            $(this).children(".text").text("取消");
            $(".checkall input:enabled").prop("checked", true);
        } else {
            $(this).children(".text").text("全选");
            $(".checkall input:enabled").prop("checked", false);
        }
        var form = layui.form;
        form.render();
    })
    $("#ComListDelete").click(function () {
        __doPostBack('multiDelete','')
    })
});


function log(data) {
    console.log(data);
}
function logJson(data) {
    console.log(JSON.stringify(data));
}

function showToast(text){
    parent.layer.msg(text)
}

function hideToast(){
    // appcan.window.closeToast();
}

function showConfirm (message,functionConfirm,functionCancel) {
    parent.layer.open({
        content: message
        ,btn: ['确认','取消']
        ,yes: function(index, layero){
            //按钮【按钮一】的回调
            functionConfirm()
        }
        ,btn2: function(index, layero){
            functionCancel()
        }
        ,cancel: function(){
            //右上角关闭回调
            layer.msg("已取消")
            functionCancel()
        }
    });
}


var form = layui.form;
var layer = layui.layer;
form.on('submit(mainform)', function(data){
    var postUrl = data.form.action;
    apiPost(postUrl,data.field,function (res) {
        console.log(res)
        if (res.d) {
            // showToast(res.i)
            showConfirm(res.i, function () {
                log(111)
                parent.layer.closeAll();
                goto(res.d)
            }, function () {
                parent.layer.closeAll();
                goto(res.d)
            });
        }else {
            showToast(res.i)
        }
    })
    return false;
});
function goto(url) {

    log("goto")
    location.href = url;
}


function showPicInList(URL) {
    parent.layer.open({
        type: 1
        ,title: false //不显示标题栏
        ,closeBtn: false
        ,area: '60vw;'
        ,shade: 0.8
        ,id: 'LAY_layuipro' //设定一个id，防止重复弹出
        ,btn: ['关闭']
        ,btnAlign: 'c'
        ,moveType: 0 //拖拽模式，0或者1
        ,content: '<div style="padding: 50px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;">' +
        '<img src="'+URL+'" alt="" style="width: 100%;height: auto;" />' +
        '</div>'
        ,success: function(layero){
            var btn = layero.find('.layui-layer-btn');
            btn.find('.layui-layer-btn0').attr({

            });
        }
    });
}